package com.icloud.cer.rest.msg;

import java.io.DataInput;
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;


public class BDataFilterInputStream extends FilterInputStream{

	private char flag;
    private DataInput input;
    
	protected BDataFilterInputStream(InputStream in) {
		super(in);
	}
	
	public BDataFilterInputStream(InputStream is, char flag) {
		super(is);
		this.flag = flag;
		if(flag == 'b') {
			input = new DataInputStream(is);
			in = new DataInputStream(is);
		} else {
			input = new LDataFilterInputStream(is);
		}
    }

	public final double readDouble() throws IOException {
		return Double.longBitsToDouble(readLong());
	}

	public final float readFloat() throws IOException {
		return Float.intBitsToFloat(readInt());
	}

	public int readInt() throws IOException {
		return input.readInt();
	}

	public short readShort() throws IOException {
		return input.readShort();
	}

	public final int read(byte b[]) throws IOException {
		return in.read(b, 0, b.length);
	}

	public final long readLong() throws IOException {
		return input.readLong();
	}

	public final void readFully(byte b[], int off, int len) throws IOException {
		input.readFully(b, off, len);
	}

	public final int skipBytes(int n) throws IOException {
		return input.skipBytes(n);
	}

	public final byte readByte() throws IOException {
		int ch = in.read();
		if (ch < 0) {
			throw new EOFException();
		}
		return (byte) (ch);
	}

	public char getFlag() {
		return flag;
	}

}
